﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MonitorPlan
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {

                if(Session["ClientId"]==null)
                {
                    Response.Redirect("ClientLogin.aspx");
                }
                else
                {
                    if (Session["HouseId"]!=null)
                    {
                        this.HiddenField1.Value = Session["HouseId"].ToString();
                        this.lb.Text = Session["HouseId"].ToString();
                    }
                   
                    this.lb.Visible = false;
                    string sql = @"select [transaction].toolid, tool.toolname, [transaction].transactionid,[transaction].light,[transaction].[date],[transaction].[time],[transaction].ampm from [transaction] ";
                    sql += "inner join tool on [transaction].toolid=tool.toolid where [transaction].houseid=" + Session["HouseId"].ToString();
                    sql += " and [transaction].[date]='" + DateTime.Now.ToShortDateString() + "' order by [transaction].transactionid desc";
                    this.ds1.SelectCommand = sql;
                    this.rp1.DataBind();
                }
            }
        }
        [System.Web.Services.WebMethod]
        public static string ReBind(string hid)
        {
            Default d = new Default();
            string sql = @"select [transaction].toolid, tool.toolname, [transaction].light,[transaction].[date],[transaction].[time],[transaction].ampm from [transaction] ";
            sql += "inner join tool on [transaction].toolid=tool.toolid where [transaction].houseid="+hid;
            SqlDataSource s = new SqlDataSource();
            s = d.ds1;
            s.SelectCommand = sql;
           // d.ds1.SelectCommand = sql;
            Repeater r = new Repeater();
            r = d.rp1;
            r.DataBind();
            //d.rp1.DataBind();
            //d.UpdatePanel1.Update();
            return sql;
        }
    }
}